package cn.enilu.flash.service.task.job;

import cn.enilu.flash.bean.entity.system.User;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.service.system.UserService;
import cn.enilu.flash.service.task.JobExecuter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Component
public class UserJob extends JobExecuter {
    @Autowired
    private UserService userService;
    @Override
    public void execute(Map<String, Object> dataMap) throws Exception {
        List<SearchFilter> searchFilters = new ArrayList<>();
        searchFilters.add(new SearchFilter("isVip", SearchFilter.Operator.EQ,1));
        searchFilters.add(new SearchFilter("vipExpirationDate", SearchFilter.Operator.LTE,new Date()));
        List<User> users = userService.queryAll(searchFilters);
        for (User user:users){
            user.setIsVip(0);// 使vip过期
            userService.update(user);
        }
    }
}
